import { createRouter, createWebHistory } from 'vue-router';
import routes from "@/router/moudle/index.js";
import { Message as ElMessage } from '@arco-design/web-vue';
const router = createRouter({
    history: createWebHistory(), // 使用 HTML5 History 模式
    routes,
});

router.beforeEach((to, from, next) => {
    const publicRoutes = ['/', '/login', '/register'];
    //记录当前路由跳转的时间戳
    const timestamp = new Date().toISOString(); // 获取当前时间戳（ISO 格式）
    if (publicRoutes.includes(to.path)) {
        return next();
    }
    //检查用户是否已登录
    if (to.meta.requiresAuth && !localStorage.getItem('token')) {
      ElMessage.error(`[${timestamp}] 未登录，跳转到登录页面`);
        next('/login'); // 跳转到登录页面
    } else {
        ElMessage.success(`[${timestamp}] 用户已登录，继续导航到: ${to.path}`);
        next();
    }
});

export default router;
